#ifndef _CANARY2_CORO_SLEEPING_SUSPEND_MANAGER_H_
#define _CANARY2_CORO_SLEEPING_SUSPEND_MANAGER_H_

#include <chrono>
#include "../sys/timerbase.h"
#include "../sys/task_manager.h"
#include "../sys/scheduler_concepts.h"
#include "../util/schedule_bind.h"

namespace wilson::coro
{
    template<sys::scheduler Schr>
    class sleeping_suspend_manager
    {
    public:
        sleeping_suspend_manager(sys::timerbase& timer, Schr& schr)
            : ssm_timer{ timer }, ssm_scheduler{ schr }
        {
        }

        template<sys::scheduler S>
        void add_task(
            S& schr, 
            ::std::coroutine_handle<> h, 
            ::std::chrono::milliseconds timeout)
        {
            ssm_timer.add_task(
                timeout, 
                util::schedule_bind(schr, h)
            );
        }

        void add_task(
            ::std::coroutine_handle<> h,
            ::std::chrono::milliseconds timeout)
        {
            add_task(ssm_scheduler, h, timeout);
        }

        void operator()()
        {
            ssm_timer.do_all_timeout();
        }

    private:
        sys::timerbase& ssm_timer;
        Schr& ssm_scheduler;
    };
}

#endif
